<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>


<style>


</style>

<script>




    class View{
        constructor (options)
        {
            this.data = options.data;
            this.ndata = [];
            this.methods = options.methods;
            let _this = this;
            for(let item in options.data)
            {
              
                Object.defineProperty(this.data,item,{
                         get:function(){
                           return _this.ndata[item];
                     },
                     set:function(newValue){
                        for(let method in _this.methods)
                        {
                            if(method==item+'Change'){
                                _this.ndata[item] = newValue
                                _this.methods[method](newValue)
                            }

                        }
                     }
                 })
            }
            return this;
        }
        
        set ( name ,data )
        {
            this.data[name] = data;
        }
        get(name)
        {
             return this.data[name]
        }
        
    }
   var Vue = new View({
        data:{
            name:[],
            sex:"cc"
        },
        methods:{
            nameChange:function(a)
            {
                  console.log('name被改了',a)
            },
            sexChange:function(a){
                console.log('sex被改了',a)
            }
        }
    })
    Vue.set('name',[{id:1,name:"name1"},{id:2,name:"name2"},{id:3,name:"name3"}]);
     Vue.set('name',[{id:1,name:"name1"},{id:2,name:"name2"},{id:3,name:"hahah"}]);
    Vue.set('sex','new sex');
    console.log(Vue.get('name'),333);
    console.log(Vue.get('sex'),999);

  
</script>
</body>
</html>